<?php

use Illuminate\Database\Seeder;
use App\Lib\Util\PinyinConvertor;
use App\Province;
use App\City;
use App\District;

class CityTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->saveCities();
    }

    private function saveCities()
    {
        $provinces = $this->initProvince();
        $cities = $this->initCity();
        $provinceCount = count($provinces);
        for ($i=0; $i<$provinceCount; $i++) {
            $province = &$provinces[$i];
            $provinceCity = &$province['citys'];
            $zxsCityDist = &$province['zxs_dist'];
            foreach ($cities as $city) {
                if ($city['province_id'] == $province['province_id']){
                    if ($city['is_zxs_dist'] == 0) {
                        array_push($provinceCity, $city);
                    } else {
                        array_push($zxsCityDist, $city);
                    }
                }
            }
        }

        $pinyinConvertor = new PinyinConvertor();

        for ($i=0; $i<$provinceCount; $i++) {
            $sprovince = $provinces[$i];
            $provinceCode = $pinyinConvertor->getAllPY(iconv('UTF-8', 'gbk', $sprovince['province_name']));
            $provinceCode = $this->getProvinceCode($provinceCode);
            $provinceModel = Province::create([
                'name'  => $sprovince['province_name'],
                'full_name' => $sprovince['province_full_name'],
                'code' => $provinceCode,
                'sort_order' => $sprovince['province_order'],
                'is_direct_city' => $sprovince['is_zxs'],
            ]);
            $cities = $sprovince['citys'];
            $cityId = -1;
            foreach ($cities as $city) {
                $cityCode = $pinyinConvertor->getAllPY(iconv('UTF-8', 'gbk', $city['city_name']));
                $cityCode = $this->getCityCode($cityCode);
                $cityModel = City::create([
                    'name'  => $city['city_name'],
                    'full_name' => $city['city_full_name'],
                    'code'  => $cityCode,
                    'sort_order' => $city['city_order'],
                    'region_code' => $city['city_region_code'],
                    'province_id' => $provinceModel->id,
                ]);
                $cityId = $cityModel->id;
            }

            if ($sprovince['is_zxs'] == 1 && $cityId != -1) {
                $zxsDists = $sprovince['zxs_dist'];
                foreach ($zxsDists as $zxsDist) {
                    $district = District::create([
                        'name' => $zxsDist['city_name'],
                        'full_name' => $zxsDist['city_full_name'],
                        'sort_order' => $zxsDist['city_order'],
                        'city_id' => $cityId
                    ]);
                }
            }

            echo $provinceModel->full_name."数据导入完毕\n";
        }
    }

    private function getProvinceCode($provinceCode)
    {
        $sameCodeProvince = Province::findByCode($provinceCode);
        if (isset($sameCodeProvince)) {
            $provinceCode .= '_1';
            return $this->getProvinceCode($provinceCode);
        }
        return $provinceCode;
    }

    private function getCityCode($cityCode)
    {
        $sameCodeCity = City::findByCode($cityCode);
        if (isset($sameCodeCity)) {
            $cityCode .= '_1';
            return $this->getCityCode($cityCode);
        }
        return $cityCode;
    }

    private function initProvince()
    {
        $province = [
            [32, '北京','北京市',1,1,'01'],
            [33, '上海','上海市',2,1,'02'],
            [34, '天津','天津市',3,1,'03'],
            [35, '重庆','重庆市',4,1,'04'],
            [36, '黑龙江','黑龙江省',5,0,'05'],
            [37, '吉林','吉林省',6,0,'06'],
            [38,'辽宁','辽宁省',7,0,'07'],
            [39,'内蒙古','内蒙古自治区',8,0,'08'],
            [40,'河北','河北省',9,0,'09'],
            [41,'山东','山东省',10,0,'10'],
            [42,'山西','山西省',11,0,'11'],
            [43,'陕西','陕西省',12,0,'12'],
            [44,'宁夏','宁夏自治区',13,0,'13'],
            [45,'甘肃','甘肃省',14,0,'14'],
            [46,'青海','青海省',15,0,'15'],
            [47,'新疆','新疆自治区',16,0,'16'],
            [48,'江苏','江苏省',17,0,'17'],
            [49,'安徽','安徽省',18,0,'18'],
            [50,'浙江','浙江省',19,0,'19'],
            [51,'河南','河南省',20,0,'20'],
            [52,'湖北','湖北省',21,0,'21'],
            [53,'湖南','湖南省',22,0,'22'],
            [54,'江西','江西省',23,0,'23'],
            [55,'福建','福建省',24,0,'24'],
            [56,'广东','广东省',25,0,'25'],
            [57,'广西','广西自治区',26,0,'26'],
            [58,'四川','四川省',27,0,'27'],
            [59,'海南','海南省',28,0,'28'],
            [60,'云南','云南省',29,0,'29'],
            [61,'贵州','贵州省',30,0,'30'],
            [62,'西藏','西藏自治区',31,0,'31'],
        ];
        $provinceCount = count($province);
        $provinces = [];
        for ($i=0; $i<$provinceCount; $i++) {
            $fields = $province[$i];
            array_push($provinces, [
                'province_id' => $fields[0],
                'province_name' => $fields[1],
                'province_full_name' => $fields[2],
                'province_order' => $fields[3],
                'is_zxs' => $fields[4],
                'province_code' => $fields[5],
                'citys'  => [],
                'zxs_dist' => [],
            ]);
        }
        return $provinces;
    }

    private function initCity()
    {
        $citys = "(130,32,'北京','北京市',1,0,'010'),(131,32,'东城','东城区',1,1,'01001'),(132,32,'西城','西城区',2,1,'01002'),(133,32,'宣武','宣武区',3,1,'01003'),(134,32,'崇文','崇文区',4,1,'01004'),(135,32,'朝阳','朝阳区',5,1,'01005'),(136,32,'海淀','海淀区',6,1,'01006'),(137,32,'丰台','丰台区',7,1,'01007'),(138,32,'石景山','石景山区',8,1,'01008'),(139,32,'房山','房山区',9,1,'01009'),(140,32,'门头沟','门头沟区',10,1,'01010'),(141,32,'通州','通州区',11,1,'01011'),(142,32,'顺义','顺义区',12,1,'01012'),(143,32,'昌平','昌平区',13,1,'01013'),(144,32,'大兴','大兴区',14,1,'01014'),(145,32,'怀柔','怀柔区',15,1,'01015'),(146,32,'平谷','平谷区',16,1,'01016'),(147,32,'延庆','延庆县',17,1,'01017'),(148,32,'密云','密云县',18,1,'01018'),(149,33,'上海','上海市',1,0,'021'),(150,33,'静安','静安区',1,1,'02101'),(151,33,'卢湾','卢湾区',2,1,'02102'),(152,33,'长宁','长宁区',3,1,'02103'),(153,33,'黄浦','黄浦区',4,1,'02104'),(154,33,'徐汇','徐汇区',5,1,'02105'),(155,33,'普陀','普陀区',6,1,'02106'),(156,33,'虹口','虹口区',7,1,'02107'),(157,33,'闸北','闸北区',8,1,'02108'),(158,33,'杨浦','杨浦区',9,1,'02109'),(159,33,'宝山','宝山区',10,1,'02110'),(160,33,'闵行','闵行区',11,1,'02111'),(161,33,'嘉定','嘉定区',12,1,'02112'),(162,33,'浦东','浦东新区',13,1,'02113'),(163,33,'松江','松江区',14,1,'02114'),(164,33,'金山','金山区',15,1,'02115'),(165,33,'青浦','青浦区',16,1,'02116'),(166,33,'南汇','南汇区',17,1,'02117'),(167,33,'奉贤','奉贤区',18,1,'02118'),(168,33,'崇明','崇明县',19,1,'02119'),(169,34,'天津','天津市',1,0,'022'),(170,34,'和平','和平区',1,1,'02201'),(171,34,'河北','河北区',2,1,'02202'),(172,34,'河东','河东区',3,1,'02203'),(173,34,'河西','河西区',4,1,'02204'),(174,34,'南开','南开区',5,1,'02205'),(175,34,'红桥','红桥区',6,1,'02206'),(176,34,'东丽','东丽区',7,1,'02207'),(177,34,'西青','西青区',8,1,'02208'),(178,34,'津南','津南区',9,1,'02209'),(179,34,'北辰','北辰区',10,1,'02210'),(180,34,'武清','武清区',11,1,'02211'),(181,34,'宝坻','宝坻区',12,1,'02212'),(182,34,'滨海','滨海新区',13,1,'02213'),(183,34,'蓟县','蓟县',14,1,'02214'),(184,34,'静海','静海县',15,1,'02215'),(185,34,'宁河','宁河县',16,1,'02216'),(186,35,'重庆','重庆市',1,0,'023'),(187,35,'渝中','渝中区',1,1,'02301'),(188,35,'大渡口','大渡口区',2,1,'02302'),(189,35,'江北','江北区',3,1,'02303'),(190,35,'沙坪坝','沙坪坝区',4,1,'02304'),(191,35,'九龙坡','九龙坡区',5,1,'02305'),(192,35,'南岸','南岸区',6,1,'02306'),(193,35,'北碚','北碚区',7,1,'02307'),(194,35,'綦江','綦江区',8,1,'02308'),(195,35,'大足','大足区',9,1,'02309'),(196,35,'渝北','渝北区',10,1,'02310'),(197,35,'巴南','巴南区',11,1,'02311'),(198,35,'黔江','黔江区',12,1,'02312'),(199,35,'长寿','长寿区',13,1,'02313'),(200,35,'江津','江津区',14,1,'02314'),(201,35,'合川','合川区',15,1,'02315'),(202,35,'永川','永川区',16,1,'02316'),(203,35,'南川','南川区',17,1,'02317'),(204,35,'璧山','璧山区',18,1,'02318'),(205,35,'铜梁','铜梁区',19,1,'02319'),(206,35,'万州','万州区',20,1,'02320'),(207,35,'涪陵','涪陵区',21,1,'02321'),(208,35,'潼南','潼南县',22,1,'02322'),(209,35,'荣昌','荣昌县',23,1,'02323'),(210,35,'梁平','梁平县',24,1,'02324'),(211,35,'城口','城口县',25,1,'02325'),(212,35,'丰都','丰都县',26,1,'02326'),(213,35,'垫江','垫江县',27,1,'02327'),(214,35,'武隆','武隆县',28,1,'02328'),(215,35,'忠县','忠县',29,1,'02329'),(216,35,'开县','开县',30,1,'02330'),(217,35,'云阳','云阳县',31,1,'02331'),(218,35,'奉节','奉节县',32,1,'02332'),(219,35,'巫山','巫山县',33,1,'02333'),(220,35,'巫溪','巫溪县',34,1,'02334'),(221,35,'石柱','石柱土家族自治县',35,1,'02335'),(222,35,'秀山','秀山土家族苗族自治县',36,1,'02336'),(223,35,'酉阳','酉阳土家族苗族自治县',37,1,'02337'),(224,35,'彭水','彭水苗族土家族自治县',38,1,'02338'),(225,56,'广州','广州市',1,0,'020'),(226,56,'深圳','深圳市',2,0,'0755'),(227,56,'佛山','佛山市',3,0,'0757'),(228,56,'珠海','珠海市',4,0,'0756'),(229,56,'东莞','东莞市',5,0,'0769'),(230,56,'潮州','潮州市',6,0,'0768'),(231,56,'汕头','汕头市',7,0,'0754'),(232,56,'韶关','韶关市',8,0,'0751'),(233,56,'江门','江门市',9,0,'0750'),(234,56,'惠州','惠州市',10,0,'0752'),(235,56,'梅州','梅州市',11,0,'0753'),(236,56,'肇庆','肇庆市',12,0,'0758'),(237,56,'湛江','湛江市',13,0,'0759'),(238,56,'中山','中山市',14,0,'0760'),(239,56,'河源','河源市',15,0,'0762'),(240,56,'清远','清远市',16,0,'0763'),(241,56,'云浮','云浮市',17,0,'0766'),(242,56,'汕尾','汕尾市',18,0,'0660'),(243,56,'阳江','阳江市',19,0,'0662'),(244,56,'揭阳','揭阳市',20,0,'0663'),(245,56,'茂名','茂名市',21,0,'0668'),(246,36,'哈尔滨','哈尔滨市',1,0,'0451'),(247,36,'齐齐哈尔','齐齐哈尔市',2,0,'0452'),(248,36,'鸡西','鸡西市',3,0,'0467'),(249,36,'鹤岗','鹤岗市',4,0,'0468'),(250,36,'双鸭山','双鸭山市',5,0,'0469'),(251,36,'大庆','大庆市',6,0,'0459'),(252,36,'伊春','伊春市',7,0,'0458 '),(253,36,'佳木斯','佳木斯市',8,0,'0454'),(254,36,'七台河','七台河市',9,0,'0464'),(255,36,'牡丹江','牡丹江市',10,0,'0453'),(256,36,'黑河','黑河市',11,0,'0456'),(257,36,'绥化','绥化市',12,0,'0455'),(258,36,'大兴安岭','大兴安岭地区',13,0,'0457'),(259,37,'长春','长春市',1,0,'0431'),(260,37,'吉林','吉林市',2,0,'0432'),(261,37,'四平','四平市',3,0,'0434'),(262,37,'辽源','辽源市',4,0,'0437'),(263,37,'通化','通化市',5,0,'0435'),(264,37,'白山','白山市',6,0,'0439'),(265,37,'松原','松原市',7,0,'0438'),(266,37,'白城','白城市',8,0,'0436'),(267,37,'延边','延边自治州',9,0,'0433'),(268,37,'长白山','长白山管委会',10,0,'0439'),(269,37,'梅河口','梅河口市',11,0,''),(270,37,'公主岭','公主岭市',12,0,''),(271,38,'沈阳','沈阳市',1,0,'024'),(272,38,'大连','大连市',2,0,'0411'),(273,38,'鞍山','鞍山市',3,0,'0412'),(274,38,'抚顺','抚顺市',4,0,'02401'),(275,38,'本溪','本溪市',5,0,'0414'),(276,38,'丹东','丹东市',6,0,'0415'),(277,38,'锦州','锦州市',7,0,'0416'),(278,38,'营口','营口市',8,0,'0417'),(279,38,'阜新','阜新市',9,0,'0418'),(280,38,'辽阳','辽阳市',10,0,'0419'),(281,38,'盘锦','盘锦市',11,0,'0427'),(282,38,'铁岭','铁岭市',12,0,'02402'),(283,38,'朝阳市','朝阳市',13,0,'0421'),(284,38,'葫芦岛','葫芦岛市',14,0,'0429'),(285,55,'福州','福州市',1,0,'0591'),(286,55,'厦门','厦门市',2,0,'0592'),(287,55,'莆田','莆田市',3,0,'0594'),(288,55,'三明','三明市',4,0,'0598'),(289,55,'泉州','泉州市',5,0,'0595'),(290,55,'漳州','漳州市',6,0,'0596'),(291,55,'南平','南平市',7,0,'0599'),(292,55,'龙岩','龙岩市',8,0,'0597'),(293,55,'宁德','宁德市',9,0,'0593'),(294,57,'南宁','南宁市',1,0,'0771'),(295,57,'柳州','柳州市',2,0,'0772'),(296,57,'桂林','桂林市',3,0,'0773'),(297,57,'梧州','梧州市',4,0,'0774'),(298,57,'北海','北海市',5,0,'0779'),(299,57,'防城港','防城港市',6,0,'0770'),(300,57,'钦州','钦州市',7,0,'0777'),(301,57,'贵港','贵港市',8,0,'0775'),(302,57,'玉林','玉林市',9,0,'077501'),(303,57,'百色','百色市',10,0,'0776'),(304,57,'贺州','贺州市',11,0,'0774'),(305,57,'河池','河池市',12,0,'0778'),(306,57,'来宾','来宾市',13,0,'077202'),(307,57,'崇左','崇左市',14,0,'077101'),(308,50,'杭州','杭州市',1,0,'0571'),(309,50,'宁波','宁波市',2,0,'0574'),(310,50,'温州','温州市',3,0,'0577'),(311,50,'嘉兴','嘉兴市',4,0,'0573'),(312,50,'湖州','湖州市',5,0,'0572'),(313,50,'绍兴','绍兴市',6,0,'0575'),(314,50,'金华','金华市',7,0,'0579'),(315,50,'衢州','衢州市',8,0,'0570'),(316,50,'舟山','舟山市',9,0,'0580'),(317,50,'台州','台州市',10,0,'0576'),(318,50,'丽水','丽水市',11,0,'0578'),(319,48,'南京','南京市',1,0,'025'),(320,48,'无锡','无锡市',2,0,'0510'),(321,48,'苏州','苏州市',3,0,'0512'),(322,48,'常州','常州市',4,0,'0519'),(323,48,'徐州','徐州市',5,0,'0516'),(324,48,'南通','南通市',6,0,'0513'),(325,48,'连云港','连云港市',7,0,'0518'),(326,48,'淮安','淮安市',8,0,'0517'),(327,48,'盐城','盐城市',9,0,'0515'),(328,48,'扬州','扬州市',10,0,'0514'),(329,48,'镇江','镇江市',11,0,'0511'),(330,48,'泰州','泰州市',12,0,'0523'),(331,48,'宿迁','宿迁市',13,0,'0527'),(332,39,'呼和浩特','呼和浩特市',1,0,'0471'),(333,39,'包头','包头市',2,0,'0472'),(334,39,'乌海','乌海市',3,0,'0473'),(335,39,'赤峰','赤峰市',4,0,'0476'),(336,39,'通辽','通辽市',5,0,'0475'),(337,39,'鄂尔多斯','鄂尔多斯市',6,0,'0477'),(338,39,'呼伦贝尔','呼伦贝尔市',7,0,'0470'),(339,39,'巴彦淖尔','巴彦淖尔市',8,0,'0478'),(340,39,'乌兰察布','乌兰察布市',9,0,'0474'),(341,39,'兴安盟','兴安盟',10,0,'0482'),(342,39,'锡林郭勒盟','锡林郭勒盟',11,0,'0479'),(343,39,'阿拉善盟','阿拉善盟',12,0,'0483'),(344,49,'合肥','合肥市',1,0,'0551'),(345,49,'芜湖','芜湖市',2,0,'0553'),(346,49,'蚌埠','蚌埠市',3,0,'0552'),(347,49,'淮南','淮南市',4,0,'0554'),(348,49,'马鞍山','马鞍山市',5,0,'0555'),(349,49,'淮北','淮北市',6,0,'0561'),(350,49,'铜陵','铜陵市',7,0,'0562'),(351,49,'安庆','安庆市',8,0,'0556'),(352,49,'黄山','黄山市',9,0,'0559'),(353,49,'滁州','滁州市',10,0,'0550'),(354,49,'阜阳','阜阳市',11,0,'0558'),(355,49,'宿州','宿州市',12,0,'0557'),(356,49,'六安','六安市',13,0,'0564'),(357,49,'亳州','亳州市',14,0,'0558'),(358,49,'池州','池州市',15,0,'0566'),(359,49,'宣城','宣城市',16,0,'0563'),(360,51,'郑州','郑州市',1,0,'0371'),(361,51,'开封','开封市',2,0,'0378'),(362,51,'洛阳','洛阳市',3,0,'0379'),(363,51,'平顶山','平顶山市',4,0,'0375'),(364,51,'安阳','安阳市',5,0,'0372'),(365,51,'鹤壁','鹤壁市',6,0,'0392'),(366,51,'新乡','新乡市',7,0,'0373'),(367,51,'焦作','焦作市',8,0,'0391'),(368,51,'濮阳','濮阳市',9,0,'0393'),(369,51,'许昌','许昌市',10,0,'0374'),(370,51,'漯河','漯河市',11,0,'0395'),(371,51,'三门峡','三门峡市',12,0,'039801'),(372,51,'商丘','商丘市',13,0,'0370'),(373,51,'周口','周口市',14,0,'0394'),(374,51,'驻马店','驻马店市',15,0,'0396'),(375,51,'南阳','南阳市',16,0,'0377'),(376,51,'信阳','信阳市',17,0,'0376'),(377,51,'济源','济源市',18,0,'039101'),(378,52,'武汉','武汉市',1,0,'027'),(379,52,'黄石','黄石市',2,0,'0714'),(380,52,'十堰','十堰市',3,0,'0719'),(381,52,'宜昌','宜昌市',4,0,'0717'),(382,52,'襄阳','襄阳市',5,0,'0710'),(383,52,'鄂州','鄂州市',6,0,'0711'),(384,52,'荆门','荆门市',7,0,'0724'),(385,52,'孝感','孝感市',8,0,'0712'),(386,52,'荆州','荆州市',9,0,'0716'),(387,52,'黄冈','黄冈市',10,0,'0713'),(388,52,'咸宁','咸宁市',11,0,'0715'),(389,52,'随州','随州市',12,0,'0722'),(390,52,'恩施','恩施自治州',13,0,'0718'),(391,52,'仙桃','仙桃市',14,0,'0728'),(392,52,'潜江','潜江市',15,0,'072801'),(393,52,'天门','天门市',16,0,'072802'),(394,52,'神农架','神农架林区',17,0,'072803'),(395,53,'长沙','长沙市',1,0,'0731'),(396,53,'湘潭','湘潭市',2,0,'0732'),(397,53,'株洲','株洲市',3,0,'0733'),(398,53,'岳阳','岳阳市',4,0,'0730'),(399,53,'衡阳','衡阳市',5,0,'0734'),(400,53,'郴州','郴州市',6,0,'0735'),(401,53,'常德','常德市',7,0,'0736'),(402,53,'益阳','益阳市',8,0,'0737'),(403,53,'娄底','娄底市',9,0,'0738'),(404,53,'邵阳','邵阳市',10,0,'0739'),(405,53,'湘西','湘西自治州',11,0,'0743'),(406,53,'怀化','怀化市',12,0,'0745'),(407,53,'永州','永州市',13,0,'0746'),(408,53,'张家界','张家界市',14,0,'0744'),(409,54,'南昌','南昌市',1,0,'0791'),(410,54,'九江','九江市',2,0,'0792'),(411,54,'上饶','上饶市',3,0,'0793'),(412,54,'抚州','抚州市',4,0,'0794'),(413,54,'宜春','宜春市',5,0,'0795'),(414,54,'吉安','吉安市',6,0,'0796'),(415,54,'赣州','赣州市',7,0,'0797'),(416,54,'景德镇','景德镇市',8,0,'0798'),(417,54,'萍乡','萍乡市',9,0,'0799'),(418,54,'新余','新余市',10,0,'0790'),(419,54,'鹰潭','鹰潭市',11,0,'0701'),(420,58,'成都','成都市',1,0,'028'),(421,58,'自贡','自贡市',2,0,'0813'),(422,58,'攀枝花','攀枝花市',3,0,'0812'),(423,58,'泸州','泸州市',4,0,'0830'),(424,58,'德阳','德阳市',5,0,'0838'),(425,58,'绵阳','绵阳市',6,0,'0816'),(426,58,'广元','广元市',7,0,'0839'),(427,58,'遂宁','遂宁市',8,0,'0825'),(428,58,'内江','内江市',9,0,'0832'),(429,58,'乐山','乐山市',10,0,'0833'),(430,58,'南充','南充市',11,0,'0817'),(431,58,'眉山','眉山市',12,0,'02801'),(432,58,'宜宾','宜宾市',13,0,'0831'),(433,58,'广安','广安市',14,0,'0826'),(434,58,'达州','达州市',15,0,'0818'),(435,58,'雅安','雅安市',16,0,'0835'),(436,58,'巴中','巴中市',17,0,'0827'),(437,58,'资阳','资阳市',18,0,'02802'),(438,58,'阿坝','阿坝自治州',19,0,'0837'),(439,58,'甘孜','甘孜自治州',20,0,'0836'),(440,58,'凉山','凉山自治州',21,0,'0834'),(441,59,'海口','海口市',1,0,'0898'),(442,59,'三亚','三亚市',2,0,'089801'),(443,59,'儋州','儋州市',3,0,'089802'),(444,62,'拉萨','拉萨市',1,0,'0891'),(445,62,'昌都','昌都市',2,0,'089101'),(446,62,'日喀则','日喀则市',3,0,'0892'),(447,62,'林芝','林芝市',4,0,'089102'),(448,62,'山南','山南地区',5,0,'0893'),(449,62,'那曲','那曲地区',6,0,'089301'),(450,62,'阿里','阿里地区',7,0,'089302'),(451,63,'台北','台北市',1,0,'0088601'),(452,63,'新北','新北市',2,0,'0088602'),(453,63,'桃园','桃园市',3,0,'0088603'),(454,63,'台中','台中市',4,0,'0088604'),(455,63,'台南','台南市',5,0,'0088605'),(456,63,'高雄','高雄市',6,0,'0088606'),(457,63,'基隆','基隆市',7,0,'0088607'),(458,63,'新竹','新竹市',8,0,'0088608'),(459,63,'嘉义','嘉义市',9,0,'0088609'),(460,60,'昆明','昆明市',1,0,'0871'),(461,60,'曲靖','曲靖市',2,0,'0874'),(462,60,'玉溪','玉溪市',3,0,'0877'),(463,60,'保山','保山市',4,0,'0875'),(464,60,'昭通','昭通市',5,0,'0870'),(465,60,'丽江','丽江市',6,0,'0888'),(466,60,'普洱','普洱市',7,0,'0879'),(467,60,'临沧','临沧市',8,0,'0883'),(468,60,'德宏','德宏自治州',9,0,'0692'),(469,60,'怒江','怒江族自治州',10,0,'0886'),(470,60,'迪庆','迪庆自治州',11,0,'0887'),(471,60,'大理','大理自治州',12,0,'0872'),(472,60,'楚雄','楚雄自治州',13,0,'0878'),(473,60,'红河','红河自治州',14,0,'0873'),(474,60,'文山','文山自治州',15,0,'0876'),(475,60,'西双版纳','西双版纳自治州',16,0,'0691'),(476,61,'贵阳','贵阳市',1,0,'0851'),(477,61,'六盘水','六盘水市',2,0,'0858'),(478,61,'遵义','遵义市',3,0,'0852'),(479,61,'铜仁','铜仁市',4,0,'0856'),(480,61,'黔西南','黔西南自治州',5,0,'0859'),(481,61,'毕节','毕节市',6,0,'0857'),(482,61,'安顺','安顺市',7,0,'0853'),(483,61,'黔东南','黔东南自治州 	',8,0,'0855'),(484,61,'黔南','黔南布自治州',9,0,'0854'),(485,40,'石家庄','石家庄市',1,0,'0311'),(486,40,'唐山','唐山市',2,0,'0315'),(487,40,'秦皇岛','秦皇岛市',3,0,'0335'),(488,40,'邯郸','邯郸市',4,0,'0310'),(489,40,'邢台','邢台市',5,0,'0319'),(490,40,'保定','保定市',6,0,'0312'),(491,40,'张家口','张家口市',7,0,'0313'),(492,40,'承德','承德市',8,0,'0314'),(493,40,'沧州','沧州市',9,0,'0317'),(494,40,'廊坊','廊坊市',10,0,'0316'),(495,40,'衡水','衡水市',11,0,'0318'),(496,41,'济南','济南市',1,0,'0531 '),(497,41,'青岛','青岛市',2,0,'0532 '),(498,41,'淄博','淄博市',3,0,'0533'),(499,41,'枣庄','枣庄市',4,0,'0632'),(500,41,'东营','东营市',5,0,'0546'),(501,41,'烟台','烟台市',6,0,'0535'),(502,41,'潍坊','潍坊市  ',7,0,'0536'),(503,41,'济宁','济宁市',8,0,'0537'),(504,41,'泰安','泰安市',9,0,'0538'),(505,41,'威海','威海市',10,0,'0631'),(506,41,'日照','日照市',11,0,'0633'),(507,41,'滨州','滨州市',12,0,'0543'),(508,41,'德州市','德州市',13,0,'0534'),(509,41,'聊城','聊城市',14,0,'0635'),(510,41,'临沂','临沂市',15,0,'0539'),(511,41,'菏泽','菏泽市',16,0,'0530'),(512,41,'莱芜','莱芜市',17,0,'0634'),(513,42,'太原','太原市',1,0,'0351'),(514,42,'朔州','朔州市',2,0,'0349'),(515,42,'忻州','忻州市 ',3,0,'0350'),(516,42,'大同','大同市',4,0,'0352'),(517,42,'阳泉 ','阳泉市',5,0,'0353'),(518,42,'晋中','晋中市',6,0,'0354'),(519,42,'长治','长治市',7,0,'0355'),(520,42,'晋城','晋城市',8,0,'0356'),(521,42,'临汾','临汾市',9,0,'0357'),(522,42,'吕梁','吕梁市',10,0,'0358'),(523,42,'运城','运城市',11,0,'0359'),(524,43,'西安','西安市',1,0,'029'),(525,43,'咸阳','咸阳市',2,0,'0910'),(526,43,'延安','延安市',3,0,'0911'),(527,43,'榆林','榆林市',4,0,'0912'),(528,43,'渭南','渭南市',5,0,'0913'),(529,43,'商洛','商洛市',6,0,'0914'),(530,43,'安康','安康市',7,0,'0915'),(531,43,'汉中','汉中市',8,0,'0916'),(532,43,'宝鸡','宝鸡市',9,0,'0917'),(533,43,'铜川','铜川市',10,0,'0919'),(534,44,'银川','银川市',1,0,'0951'),(535,44,'石嘴山','石嘴山市',2,0,'0952'),(536,44,'吴忠','吴忠市',3,0,'0953'),(537,44,'固原','固原市',4,0,'0954'),(538,45,'兰州','兰州市',1,0,'0931'),(539,45,'临夏','临夏市 ',2,0,'0930'),(540,45,'定西','定西市',3,0,'0932'),(541,45,'平凉','平凉市',4,0,'0933'),(542,45,'西峰','西峰市',5,0,'0934'),(543,45,'武威','武威市',6,0,'0935'),(544,45,'张掖','张掖市',7,0,'0936'),(545,45,'酒泉','酒泉市',8,0,'0937'),(546,45,'天水','天水市',9,0,'0938'),(547,45,'甘南州','甘南州市',10,0,'0941'),(548,45,'白银','白银市',11,0,'0943'),(549,46,'西宁','西宁市',1,0,'0971'),(550,46,'海东','海东市',2,0,'0972'),(551,46,'同仁','同仁市',3,0,'0973'),(552,46,'共和','共和市',4,0,'0974'),(553,46,'玛沁','玛沁市',5,0,'0975'),(554,46,'玉树','玉树市',6,0,'0976'),(555,46,'德令','德令哈',7,0,'0977'),(556,47,'乌鲁木齐','乌鲁木齐市',1,0,'0991'),(557,47,'克拉玛依','克拉玛依市',2,0,'0990'),(558,47,'吐鲁番','吐鲁番市',3,0,'0995'),(559,47,'哈密','哈密市',4,0,'0902'),(560,47,'和田','和田市',5,0,'0903'),(561,47,'阿克苏','阿克苏市',6,0,'0997'),(562,47,'喀什','喀什市',7,0,'0998'),(563,47,'阿图什','阿图什市',8,0,'0908'),(564,47,'库尔勒','库尔勒市',9,0,'0996'),(565,47,'昌吉','昌吉市',10,0,'0994'),(566,47,'博乐','博乐市',11,0,'0909'),(567,47,'伊宁','伊宁市',12,0,'0999'),(568,47,'奎屯','奎屯市',13,0,'0992'),(569,47,'塔城','塔城市',14,0,'0901'),(570,47,'乌苏市','乌苏市',15,0,'0992'),(571,47,'阿勒泰','阿勒泰市',16,0,'0906'),(572,47,'石河子','石河子市',17,0,'0993'),(573,47,'阿拉尔','阿拉尔市',18,0,'0997'),(574,47,'图木舒克','图木舒克市',19,0,'0998'),(575,47,'五家渠','五家渠市',20,0,'0994')";
        $cityseg = explode('),(', $citys);
        $citycount = count($cityseg);
        for ($i=0; $i<$citycount; $i++) {
            $citystr = $cityseg[$i];
            if ($i == 0) {
                $citystr = mb_substr($citystr, 1);
            } else if ($i == $citycount-1) {
                $citystr = mb_substr($citystr, 0, mb_strlen($citystr)-1);
            }
            $fields = explode(',', $citystr);
            $city['city_name'] = mb_substr($fields[2], 1, mb_strlen($fields[2])-2);
            $city['city_full_name'] = mb_substr($fields[3], 1, mb_strlen($fields[3])-2);
            $city['province_id'] = $fields[1];
            $city['is_zxs_dist'] = $fields[5];
            $city['city_order'] = $fields[4];
            $city['city_region_code'] = $fields[6];

            $cities[$i] = $city;
        }
        return $cities;
    }
}
